// model_holder.js

import GetterJS from '@/js/getter'



function normalizeSelectionMode(mode) {
    switch (mode) {
        case "multi":
            return mode;
        case "single":
            return mode;
        default:
    }
    return 'none'
}

function normalizeSelectionItemName(name) {
    if (name == null) { return "" }
    return name + ""
}


////////////////////////////////////////////////////////////////////////////////

function Holder(vo) {
    this.vo = vo
    this.g = GetterJS.NewGetter(vo)
}

Holder.prototype = {

    GetItems() {
        return this.g.Get('fquery.items', '.', [])
    },

    GetURI() {
        return this.g.Get('fquery.uri', '.', "")
    },

    GetSelf() {
        return this.g.Get('fquery.self', '.', {})
    },

    GetWD() {
        return this.g.Get('fquery.uri', '.', "")
    },


    GetSelectionMode() {
        // string:['multi'|'single'|'none']
        let mode = this.vo.selection_mode;
        return normalizeSelectionMode(mode);
    },

    SetSelectionMode(mode) {
        this.vo.selection_mode = normalizeSelectionMode(mode);
    },

    GetCurrentSelectionItem() {
        let name = this.vo.current_selection_name;
        return normalizeSelectionItemName(name);
    },

    SetCurrentSelectionItem(name) {
        this.vo.current_selection_name = normalizeSelectionItemName(name);
    },

}

////////////////////////////////////////////////////////////////////////////////


function Hold(vo) {
    if (vo == null) {
        vo = {}
    }
    return new Holder(vo)
}



export default {
    name: "model_holder",
    New: Hold,
}
